﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wf5.Engine.Common;
using Wf5.Engine.Business;

using FCDB.Entity;

namespace Wf5.Engine.Core
{
    /// <summary>
    /// 异或类型的节点
    /// </summary>
    internal class XOrSplitNode : NodeBase, ICompleteAutomaticlly
    {
         internal XOrSplitNode(ActivityEntity activity)
            : base(activity)
        { 
        }

         internal override void AfterActivityInstanceObjectCreated()
         {
             base.ActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.XOrSplit;
         }

        #region ICompleteAutomaticlly 成员

         public GatewayExecutedResult CompleteAutomaticlly(WfProcessInstance processInstance,
            Guid transitionGUID,
            WfActivityInstance fromActivityInstance, 
            ActivityResource activityResource)
        {
            var toActivityInstance = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);

            base.InsertActivityInstance(toActivityInstance );

            base.CompleteActivityInstance(toActivityInstance.ID, activityResource);

            base.SyncActivityInstanceObjectState(NodeStateEnum.Completed);

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                TransitionTypeEnum.Forward,
                TransitionFlyingTypeEnum.NotFlying,
                activityResource.LogonUser);

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);
            return result;
        }

        #endregion
    }
}
